package org.liziyi.huffman.utils;

import java.io.BufferedInputStream;
import java.io.FileInputStream;

/**
 * 文件工具类
 *
 * @author liziyi
 */
public class FileUtils {
    /**
     * 读取文件内容
     * @param path 文件绝对路径
     * @return 文件内容
     */
    public static String readFile(String path) {
        StringBuilder sb = new StringBuilder();
        try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path))) {
            byte[] buffer = new byte[1024];
            int len;
            while((len = bis.read(buffer))!=-1){
                sb.append(new String(buffer,0,len));
            }
        } catch (Exception ex) {
            return null;
        }
        return sb.toString();
    }
}
